package com.egg.ylt.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.DateUtils;
import com.egg.ylt.pojo.BalletRecordEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sichaoqi on 2018/9/25.
 */

public class ADA_TransactionDetails extends RecyclerView.Adapter<ADA_TransactionDetails.TransactionViewHolder> {


    private Context mContext;
    private LayoutInflater mInflater;
    private List<BalletRecordEntity.ListBean> mList;

    public ADA_TransactionDetails(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mList = new ArrayList<>();
    }

    public void setmList(List<BalletRecordEntity.ListBean> list) {
        if (mList != null) {
            mList.clear();
        }
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public TransactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TransactionViewHolder(mInflater.inflate(R.layout.item_transaction_recycler_view, parent, false));
    }

    @Override
    public void onBindViewHolder(TransactionViewHolder holder, int position) {

        BalletRecordEntity.ListBean entity = mList.get(position);

        //消费时间
        holder.tvCreateTime.setText(entity.getCreateTime());

        //交易类型（0-充值，1-付款，2-提现，3-转账，4-返现）
        String payType = "";
        String tvAdd = "";
        switch (entity.getDealType()){
            case "0":
                payType = "充值";
                tvAdd = "+ ";
                break;
            case "1":
                payType = "付款";
                tvAdd = "－";
                break;
            case "2": payType = "提现";tvAdd = "－";
                break;
            case "3": payType = "转账";tvAdd = "－";
                break;
            case "4": payType = "返现";tvAdd = "+ ";
                break;
        }
        //消费金额
        holder.tvDealType.setText(payType);
        holder.tvPrice.setText(tvAdd + DateUtils.getFormattedMoney(String.valueOf(entity.getAmount())));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class TransactionViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_create_time)
        TextView tvCreateTime;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_deal_type)
        TextView tvDealType;
        public TransactionViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
